package adfc2.actions;

import adfc2.core.Creature;
import adfc2.core.Item;
import adfc2.core.World;

public class ConstructAction extends LongAction {

    public final short construction;
    public final int tgtxy;
    public final Item material;

    public ConstructAction(Creature actor, short construction, int tgtxy, Item material) {
        super(actor);
        this.construction = construction;
        this.tgtxy = tgtxy;
        this.material = material;
    }

    @Override
    protected void started() {
        assert World.near(actor.getXY(), tgtxy);
        assert (material.owner == actor);
        assert ((World.world().blocks[tgtxy] & World.MASK_IMPASSABLE) == 0);
        assert (material.type() == Item.Type.STONE || material.type() == Item.Type.BLOCK);
    }

    @Override
    protected boolean progressing(long dt) {
        return (totaltime > getConstructionTime());
    }

    private int getConstructionTime() {
        return 1000;
    }

    @Override
    protected void finished() {
        actor.removeItem(material);
        World.world().placeWall(tgtxy, material.material().ord());
    }

    @Override
    protected void interrupted() {
    }

    @Override
    public double estimateProgress() {
        return ((double) totaltime) / getConstructionTime();
    }
}
